//
//  AZWelcomeViewController.swift
//  sinaWB
//
//  Created by AzeryKiss on 16/2/27.
//  Copyright © 2016年 AzeryKiss. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage


class AZWelcomeViewController: UIViewController {
    var snapKitTopConstraint: Constraint?
    var snapKitBottomConstraint: Constraint?

    override func viewDidLoad() {
        super.viewDidLoad()

        setConstraint()
        


    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)

    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
//        snapKitTopConstraint?.updateOffset(0)
        snapKitTopConstraint?.updateOffset(100)

        print(snapKitTopConstraint)

        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 2, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { _ in
                NSNotificationCenter.defaultCenter().postNotificationName(changeNotification, object: nil)

                print("动画执行完毕")
                //切换控制器
        }
        
    }
    
    
    func setConstraint() {
        backImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.view.snp_top)
            make.left.equalTo(self.view.snp_left)
            make.right.equalTo(self.view.snp_right)
            make.bottom.equalTo(self.view.snp_bottom)
        }
        
        welView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view.snp_centerX)
           snapKitTopConstraint =  make.top.equalTo(300).constraint
//            welView.backgroundColor = UIColor.orangeColor()
            make.width.equalTo(200)
            make.height.equalTo(200)
        }
        
        userHeader.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view.snp_centerX)
            make.top.equalTo(self.welView.snp_top).offset(10)
//            snapKitBottomConstraint = make.top.equalTo(300).constraint

            make.width.equalTo(100)
            make.height.equalTo(100)
        }
        
        welMessage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.welView.snp_centerX)
            make.top.equalTo(self.userHeader.snp_bottom).offset(10)
            make.width.equalTo(100)
        }
        

    }
    
    /// 四个组件
    lazy var backImage: UIImageView = {
        let  backImage = UIImageView(image: UIImage(named: "ad_background"))
        self.view.addSubview(backImage)

//        backImage.sd_setImageWithURL(<#T##url: NSURL!##NSURL!#>, placeholderImage: <#T##UIImage!#>)
        return backImage
        
    }()
    
    lazy var welView: UIView = {
       
        let welView = UIView()
        self.view.addSubview(welView)
        return welView
        
    }()
    
    lazy var userHeader: UIImageView = {
        let  userHeader = UIImageView(image: UIImage(named: "avatar_default_big"))
        self.view.addSubview(userHeader)
        
                userHeader.layer.cornerRadius = 50
                userHeader.clipsToBounds = true
        return userHeader
        
    }()
    
    lazy var welMessage: UILabel = {
       let welMessage = UILabel()
        welMessage.text = "欢迎回来"
        welMessage.textAlignment = NSTextAlignment.Center
        self.welView.addSubview(welMessage)
        return welMessage
    }()
    

}
